<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Technoweenie::AttachmentFu::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Technoweenie::AttachmentFu::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu_rb.html">
                vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000057">after_attachment_saved</a>&nbsp;&nbsp;
      <a href="#M000056">after_resize</a>&nbsp;&nbsp;
      <a href="#M000058">before_thumbnail_saved</a>&nbsp;&nbsp;
      <a href="#M000060">copy_to_temp_file</a>&nbsp;&nbsp;
      <a href="#M000055">image?</a>&nbsp;&nbsp;
      <a href="#M000059">thumbnail_class</a>&nbsp;&nbsp;
      <a href="#M000054">validates_as_attachment</a>&nbsp;&nbsp;
      <a href="#M000061">write_to_temp_file</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000057" class="method-detail">
        <a name="M000057"></a>

        <div class="method-heading">
          <a href="#M000057" class="method-signature">
          <span class="method-name">after_attachment_saved</span><span class="method-args">(&amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Callback after an attachment has been saved either to the file system or
the DB. Only called if the file has been changed, not necessarily if the
record is updated.
</p>
<pre>
  class Foo &lt; ActiveRecord::Base
    acts_as_attachment
    after_attachment_saved do |record|
      ...
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000057-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 137</span>
137:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_attachment_saved</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
138:         <span class="ruby-identifier">write_inheritable_array</span>(<span class="ruby-identifier">:after_attachment_saved</span>, [<span class="ruby-identifier">block</span>])
139:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000056" class="method-detail">
        <a name="M000056"></a>

        <div class="method-heading">
          <a href="#M000056" class="method-signature">
          <span class="method-name">after_resize</span><span class="method-args">(&amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Callback after an image has been resized.
</p>
<pre>
  class Foo &lt; ActiveRecord::Base
    acts_as_attachment
    after_resize do |record, img|
      record.aspect_ratio = img.columns.to_f / img.rows.to_f
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000056-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 124</span>
124:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_resize</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
125:         <span class="ruby-identifier">write_inheritable_array</span>(<span class="ruby-identifier">:after_resize</span>, [<span class="ruby-identifier">block</span>])
126:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000058" class="method-detail">
        <a name="M000058"></a>

        <div class="method-heading">
          <a href="#M000058" class="method-signature">
          <span class="method-name">before_thumbnail_saved</span><span class="method-args">(&amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Callback before a thumbnail is saved. Use this to pass any necessary extra
attributes that may be required.
</p>
<pre>
  class Foo &lt; ActiveRecord::Base
    acts_as_attachment
    before_thumbnail_saved do |record, thumbnail|
      ...
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000058-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 149</span>
149:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before_thumbnail_saved</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
150:         <span class="ruby-identifier">write_inheritable_array</span>(<span class="ruby-identifier">:before_thumbnail_saved</span>, [<span class="ruby-identifier">block</span>])
151:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000060" class="method-detail">
        <a name="M000060"></a>

        <div class="method-heading">
          <a href="#M000060" class="method-signature">
          <span class="method-name">copy_to_temp_file</span><span class="method-args">(file, temp_base_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Copies the given file path to a new tempfile, returning the closed
tempfile.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000060-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000060-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 161</span>
161:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">copy_to_temp_file</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">temp_base_name</span>)
162:         <span class="ruby-identifier">returning</span> <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">temp_base_name</span>, <span class="ruby-constant">Technoweenie</span><span class="ruby-operator">::</span><span class="ruby-constant">AttachmentFu</span>.<span class="ruby-identifier">tempfile_path</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tmp</span><span class="ruby-operator">|</span>
163:           <span class="ruby-identifier">tmp</span>.<span class="ruby-identifier">close</span>
164:           <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">cp</span> <span class="ruby-identifier">file</span>, <span class="ruby-identifier">tmp</span>.<span class="ruby-identifier">path</span>
165:         <span class="ruby-keyword kw">end</span>
166:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000055" class="method-detail">
        <a name="M000055"></a>

        <div class="method-heading">
          <a href="#M000055" class="method-signature">
          <span class="method-name">image?</span><span class="method-args">(content_type)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true or false if the given content type is recognized as an image.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000055-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 112</span>
112:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">image?</span>(<span class="ruby-identifier">content_type</span>)
113:         <span class="ruby-identifier">content_types</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">content_type</span>)
114:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000059" class="method-detail">
        <a name="M000059"></a>

        <div class="method-heading">
          <a href="#M000059" class="method-signature">
          <span class="method-name">thumbnail_class</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Get the thumbnail class, which is the current attachment class by default.
Configure this with the :<a
href="ClassMethods.html#M000059">thumbnail_class</a> option.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000059-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000059-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 155</span>
155:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">thumbnail_class</span>
156:         <span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:thumbnail_class</span>] = <span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:thumbnail_class</span>].<span class="ruby-identifier">constantize</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:thumbnail_class</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Class</span>)
157:         <span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:thumbnail_class</span>]
158:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000054" class="method-detail">
        <a name="M000054"></a>

        <div class="method-heading">
          <a href="#M000054" class="method-signature">
          <span class="method-name">validates_as_attachment</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Performs common validations for attachment models.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000054-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 106</span>
106:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validates_as_attachment</span>
107:         <span class="ruby-identifier">validates_presence_of</span> <span class="ruby-identifier">:size</span>, <span class="ruby-identifier">:content_type</span>, <span class="ruby-identifier">:filename</span>
108:         <span class="ruby-identifier">validate</span>              <span class="ruby-identifier">:attachment_attributes_valid?</span>
109:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000061" class="method-detail">
        <a name="M000061"></a>

        <div class="method-heading">
          <a href="#M000061" class="method-signature">
          <span class="method-name">write_to_temp_file</span><span class="method-args">(data, temp_base_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Writes the given data to a new tempfile, returning the closed tempfile.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000061-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000061-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb, line 169</span>
169:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write_to_temp_file</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">temp_base_name</span>)
170:         <span class="ruby-identifier">returning</span> <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">temp_base_name</span>, <span class="ruby-constant">Technoweenie</span><span class="ruby-operator">::</span><span class="ruby-constant">AttachmentFu</span>.<span class="ruby-identifier">tempfile_path</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tmp</span><span class="ruby-operator">|</span>
171:           <span class="ruby-identifier">tmp</span>.<span class="ruby-identifier">binmode</span>
172:           <span class="ruby-identifier">tmp</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">data</span>
173:           <span class="ruby-identifier">tmp</span>.<span class="ruby-identifier">close</span>
174:         <span class="ruby-keyword kw">end</span>
175:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>